from utils import UtilsDriver,get_msg,get_data_json,get_data_xlsx_pandas
from page.page_home import HomeProxy
from page.page_login import LoginProxy
import pytest
from time import sleep
from tools.logger import logger

# test_case_data=get_data_json('../data/login_case_data.json')
test_case_data=get_data_xlsx_pandas('data/login_case_data.xlsx','test')

class TestLogin:
    def setup_class(self):
        UtilsDriver.get_driver(url="http://hmshop-test.itheima.net/")
        self.home_proxy=HomeProxy()
        self.login_proxy=LoginProxy()
        self.home_proxy.go_login_page()
        self.logger=logger

    def setup_method(self):
        UtilsDriver.get_driver().refresh()
        self.Failed=False
        self.reason=None
        self.data=None

    def teardown_method(self):
        if self.Failed:
            self.logger.error('错误数据:%s', self.data)
            self.logger.error('错误原因:%s',self.reason)

    def teardown_class(self):
        UtilsDriver.quite_driver()

    @pytest.mark.parametrize("username,password,code,expect",test_case_data)
    def test_login_all_fa(self,username,password,code,expect):
        self.login_proxy.login(username, password, code)
        self.data=(username, password, code)
        msg=None
        try:
            # 获取提示信息
            msg = get_msg()
            assert expect in msg
        except AssertionError as e:
            print(1,e)
            self.Failed = True
            self.reason=("EXCEPT:%s,Actual:%s", expect,msg)
            raise


    @pytest.mark.parametrize("username,password,code,expect",test_case_data)
    def test_login_all_try(self,username,password,code,expect):
        self.login_proxy.login(username, password, code)
        self.test_data=(username, password, code)
        msg=None
        try:
            # 获取提示信息
            msg = get_msg()
            assert expect in msg
        except AssertionError as e:
            # logger.error('Test Failed:',{request.node.name})
            logger.error("Test Data:%s",self.test_data)
            logger.error("EXCEPT:%s,Actual:%s", expect,msg)


    # def test_login_04(self):
    #     self.login_proxy.login("13012345678", "1234567", "8888")
    #     # 获取提示信息
    #     msg = get_mag()
    #     assert "密码错误" in msg
    #
    # def test_login_01(self):
    #     # 获取提示信息
    #     self.login_proxy.login("13012345678", "1234567", "8888")
    #     # 获取提示信息
    #     msg = get_mag()
    #     assert "密码错误" in msg
    #
    # def test_login_02(self):
    #     self.login_proxy.login("13333337777", "123456", "8888")
    #     msg = get_mag()
    #     assert "账号不存在" in msg
    #
    # def test_login_03(self):
    #     self.login_proxy.login(" ", "123456", "8888")
    #     # 获取提示信息
    #     msg = get_mag()
    #     assert "用户名不能为空" in msg

